//
//  TestViewController.m
//  TitleContentExample
//
//  Created by 唐可雄 on 2019/7/27.
//  Copyright © 2019 swustyc. All rights reserved.
//

#import "TestViewController.h"

#import <TitleContent/TitleContent.h>
#import <ChannelChoose/ChannelChoose.h>

@interface TestViewController ()<YCTitleContentViewControllerDataSource, YCTitleContentViewControllerDelegate> {
    NSArray *_temp1;
    NSArray *_temp2;
    YCTitleContentViewController *c;
}

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _temp1 = @[@"要闻",@"河北",@"财经",@"娱乐",@"体育",@"社会",@"NBA"];
    _temp2 = @[@"有声",@"家居",@"电竞",@"美容",@"电视剧",@"搏击",@"健康"];
    
    c = [[YCTitleContentViewController alloc] init];
    c.config = [[YCTitleContentConfig alloc] init];
    c.config.collectionViewCellSpace = 15;
    c.config.titleViewPos = YCTitleViewPosNormal;
    c.config.titleViewStyle = YCTitleViewStyleCollection;
    c.config.lineViewTransitionType = YCLineViewTransitionTypePull;
    c.config.lineViewShape = YCLineViewShapeRoundRect;
    c.config.collectionViewEdgeInsets = UIEdgeInsetsMake(4, 8, 4, 8);
    c.config.titleViewHeight = 40;
    c.config.textVerAlignment = YCTextVerAlignmentCenter;
    c.config.textColorSelected = [UIColor colorWithRed:10/255.f green:190/255.f blue:6/255.f alpha:1];
    c.config.textFontSelected = [UIFont systemFontOfSize:18];
    c.config.textColorUnselected = [UIColor colorWithRed:51/255.f green:51/255.f blue:51/255.f alpha:1];
    c.config.textFontUnselected = [UIFont systemFontOfSize:18];
    c.config.lineViewWidth = 22;
    c.config.lineViewHeight = 2;
    c.config.lineViewAlignment = YCLineViewAlignmentBottom;
    c.config.lineViewBackgroundColor = [UIColor colorWithRed:10/255.f green:190/255.f blue:6/255.f alpha:1];
    c.config.separatorViewColor = [UIColor colorWithRed:238/255.f green:238/255.f blue:238/255.f alpha:1];
    c.dataSource = self;
    c.delegate = self;
    [c displayInParentViewController:self];
}

- (NSUInteger)numberOfTitlesInTitleContentViewController:(YCTitleContentViewController *)titleContentVC {
    return _temp1.count;
}

- (NSString *)titleContentViewController:(YCTitleContentViewController *)titleContentVC textTitleForIndex:(NSUInteger)index {
    return _temp1[index];
}

- (UIViewController *)titleContentViewController:(YCTitleContentViewController *)titleContentVC contentViewControllerForIndex:(NSInteger)index {
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"vcDemo"];
    if (index == 0) {
        vc.view.backgroundColor = [UIColor greenColor];
    } else if (index == 1) {
        vc.view.backgroundColor = [UIColor grayColor];
    } else if (index == 2) {
        vc.view.backgroundColor = [UIColor yellowColor];
    } else if (index == 3) {
        vc.view.backgroundColor = [UIColor grayColor];
    } else if (index == 4) {
        vc.view.backgroundColor = [UIColor whiteColor];
    }
    return vc;
}

- (void)titleContentViewController:(YCTitleContentViewController *)titleContentVC didSelectAtIndex:(NSInteger)index {
    
}

- (void)channelManage {
    YCChannelCollectionVC *vc = [[YCChannelCollectionVC alloc] initWithChannelsEnable:_temp1 channelsDisable:_temp2];
    vc.sectionTitles = @[@"已选频道", @"推荐频道"];
    vc.sectionSubtitles = @[@"按住拖动调整排序", @""];
    vc.enableChannelsFixNum = 1;
    vc.title = @"频道定制";
    [vc showInViewController:self withCompletion:^(NSArray * _Nonnull channelsEnable, NSArray * _Nonnull channelsDisable) {
        self->_temp1 = channelsEnable;
        self->_temp2 = channelsDisable;
        [self->c reloadData];
    }];
}

- (UIButton *)rightButtonInTitleContentViewController:(YCTitleContentViewController *)titleContentVC {
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [button addTarget:self action:@selector(channelManage) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"channelManageButton"] forState:UIControlStateNormal];
    [button setImageEdgeInsets:UIEdgeInsetsMake(5, 7, 5, 7)];
    return button;
}

@end
